from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponseRedirect


class CustomerMiddleware(MiddlewareMixin):
    # 注意：中间件是在urls之前运行的
    def process_request(self, request):
        if not request.user.username:
            if request.path != "/crm/login":
                return HttpResponseRedirect('/crm/login')

    def process_response(self, request, response):
        return response
